A ds_grid is basically a type of two-dimensional array. 你可以通过设置整数宽和高来定义一个栅格数据结构,及其"单元格"总数(即宽和高相乘),然后在这些单元格中保存不同的数据(实数或字符串)
这种数据结构允许你设置并通过x和y值来索引网格中的数据(x和y轴均从0开始索引,上限均为-1)。你还可以设置和获取某特定范围内网格数据的总和、最大值、最小值以及平均值,因此这个数据结构是所有类型中功能最丰富的。
当访问网格数据结构时,你应该确保使用"整数"值来索引单元格坐标,否则GameMaker Studio 2将自动向下取整如果这不是你所需要的,那么在传递你要检查的索引之前,你需要先自己进行四舍五入。
下列函数都是用于处理栅格数据结构的:
- ds_grid_create
- ds_grid_destroy
- ds_grid_width
- ds_grid_height
- ds_grid_resize
- ds_grid_clear
- ds_grid_set
- ds_grid_set_disk
- ds_grid_set_grid_region
- ds_grid_set_region
- ds_grid_shuffle
- ds_grid_sort
- ds_grid_get
- ds_grid_get_max
- ds_grid_get_mean
- ds_grid_get_min
- ds_grid_get_sum
- ds_grid_get_disk_max
- ds_grid_get_disk_mean
- ds_grid_get_disk_min
- ds_grid_get_disk_sum
- ds_grid_add
- ds_grid_add_region
- ds_grid_add_disk
- ds_grid_add_grid_region
- ds_grid_multiply
- ds_grid_multiply_disk
- ds_grid_multiply_region
- ds_grid_multiply_grid_region
- ds_grid_value_exists
- ds_grid_value_disk_exists
- ds_grid_value_x
- ds_grid_value_y
- ds_grid_value_disk_x
- ds_grid_value_disk_y
- ds_grid_copy
- ds_grid_read
- ds_grid_write
出了这些特定的函数外,你还可以使用表达式(或称"访问器")来添加或修改其中的数据语法跟2维数组十分类似
grid_index[# xpos, ypos]
你还可以找到更多相关内容,比如你可以在GML总览页查看更多关于 Accessors的介绍.